<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>react-demo-09</title>
    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
    <link
      href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC&display=swap"
      rel="stylesheet"
    />
  </head>
  <style lang="scss">
    * {
      font-family: 'Noto Sans SC', sans-serif;
    }

    .title {
      display: inline-flex;
      border: 1px solid blue;
      border-radius: 3px;
    }
  </style>
  <body>
    <!-- 准备容器 -->
    <div id="main"></div>

    <!-- 引入react核心库 -->
    <script
      type="text/javascript"
      src="https://cdn.bootcdn.net/ajax/libs/react/17.0.2/umd/react.development.js"
    ></script>
    <!-- 引入react-dom，用于操作dom -->
    <script
      type="text/javascript"
      src="https://cdn.bootcdn.net/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"
    ></script>
    <!-- 引入babel，用于编译jsx -->
    <script src="https://cdn.bootcdn.net/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>

    <!-- 此处一定要写babel，用于提示babel对该内容进行编译 -->
    <script type="text/babel">
      class DemoComponent extends React.Component {
        // 直接在类中赋值定义。
        state = {
          time: new Date().toLocaleTimeString(),
        };

        constructor(props) {
          super(props);
        }

        render() {
          return (
            <h2 onClick={this.timeRefresh}>现在时间是 {this.state.time}</h2>
          );
        }
        // 使用箭头函数。
        timeRefresh = () => {
          this.setState({
            time: new Date().toLocaleTimeString(),
          });
        };
      }
      ReactDOM.render(<DemoComponent />, document.getElementById('main'));
    </script>
  </body>
</html>
